<template>
	<view>
		<view class='goods-item'>
			<view class="goods-left">
				<radio :checked="goods.goods_state" color="red" v-if='showRadio' @click="radioclick"></radio>
				<image class="goods-img" :src="goods.goods_small_logo" mode=""></image>
			</view>
			<view class="goods-right">
				<view class="goods-name">{{goods.goods_name}}</view>
				<view class="goods-jiage">
					<view class="goods-price">￥{{goods.goods_price | toFixed}}</view>
					<uni-number-box :min='1'  :value="goods.goods_count" v-if="shownum" @change="numChange" ></uni-number-box>
				</view>				
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		name: "goods-item",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			shownum: {
				type: Boolean,
				default: false
			},
		},
		data() {
			return {

			};
		},
		filters: {
			toFixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			numChange(value){
				console.log(value);
				this.$emit('numAdd',{
					goods_id:this.goods.goods_id,
					goods_count:value
				})
			},
			...mapMutations('cart_m', ['updateGoodsState']),
			xx() {
				this.$emit('click');
			},
			radioclick() {
				console.log('选中');
				const goods_id_state = {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state,
				}
				// this.updateGoodsState(goods_id_state)
				this.$emit('radioChange', goods_id_state)
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid gray;

		.goods-left {
			margin-right: 10px;
			display: flex;
			align-items: center;

			.goods-img {
				width: 100px;
				height: 100px;
				display: block;
			}
		}

		.goods-right {
			.goods-jiage{
				display: flex;
				align-items: center;
				justify-content: space-between;
				
			}
			.goods-price {
				font-size: 20px;
				margin-top: 30px;
				margin-left: 10px;
				color: red;
			}
		}
	}
</style>
